<?php

/**
 * @Project NUKEVIET 3.0 LICH CONG TAC
 * @Author PHAN DINH BAO (baocatg@gmail.com)
 * @copyright 2010
 * @createdate 12/16/2010 0:51
 */

if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );

//load config
$module_config = array();
$sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_config`";
$result = $db->sql_query( $sql );
while ( $r = $db->sql_fetchrow($result) )
{
	$module_config[ $r['tenthamso'] ] = $r['giatri'];
}

function user_of_group( $groupid ){

	global $db, $lang_module;
	
	$sql = "select users from ". NV_GROUPS_GLOBALTABLE . " where (group_id = $groupid) ";
	$result = $db->sql_query( $sql );
	$r = $db->sql_fetchrow( $result );
	
	echo "<select name='user_action' id='user_action'>";
	echo "<option value ='0'>" . $lang_module['select_user_action'] . "</option>";
	
	if( $r ){

		$sql = "select userid, full_name from ". NV_USERS_GLOBALTABLE . " where userid IN(" . $r['users'] . ") ";
		
	} else {
	
		$sql = "select userid, full_name from ". NV_USERS_GLOBALTABLE;
	
	}
		$result = $db->sql_query( $sql );
		while ( $r = $db->sql_fetchrow($result) ){
		
			echo "<option value ='" . $r['userid'] . "'>" . $r['full_name'] . "</option>";
		
		}
	

	echo "</select>\n";
}

function nv_edit_work ( $id )
{
    global $lang_global, $module_name;
    $link = "<span class=\"edit_icon\"><a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=content&amp;id=" . $id . "\">" . $lang_global['edit'] . "</a></span>";
    return $link;
}

function nv_delete_work ( $id )
{
    global $lang_global, $module_name;
    $link = "<span class=\"delete_icon\"><a href=\"javascript:void(0);\" onclick='nv_delete_work($id)'>" . $lang_global['delete'] . "</a></span>";
    return $link;
}

function user_login ( $gfx_chk, $array_login ){

    global $client_info, $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head, $openid_servers;
    
	if ( !$global_config['allowuserlogin'] ) {
	
		return "<p class='acenter'><strong>" . $lang_module['notallowuserlogin'] . "</strong></p>" ;
		
	}
	
	$content = "";
	
	if ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_name . "/login.tpl" ) )
    {
        $block_theme = $global_config['module_theme'];
    }
    elseif ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['site_theme'] . "/modules" . $module_name . "/login.tpl" ) )
    {
        $block_theme = $global_config['site_theme'];
    }
    else
    {
        $block_theme = "default";
    }

    $xtpl = new XTemplate( "login.tpl", NV_ROOTDIR . "/themes/" . $block_theme . "/modules/" . $module_name );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#loginForm').validate();
          });";
    $my_head .= "  </script>\n";
    
	$xtpl->assign( 'USER_LOGIN', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=users&amp;" . NV_OP_VARIABLE . "=login" );
    $xtpl->assign( 'USER_REGISTER', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=users&amp;" . NV_OP_VARIABLE . "=register" );
    $xtpl->assign( 'USER_LOSTPASS', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=users&amp;" . NV_OP_VARIABLE . "=lostpass" );
    $xtpl->assign( 'NICK_MAXLENGTH', NV_UNICKMAX );
    $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
    
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $array_login );
    
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.captcha' );
    }
    
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/users/openid.gif" );
        $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
        $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
        
        $assigns = array();
        foreach ( $openid_servers as $server => $value )
        {
            $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=users&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $server;
            $assigns['title'] = ucfirst( $server );
            $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/users/" . $server . ".gif";
            $assigns['img_width'] = $assigns['img_height'] = 24;
            
            $xtpl->assign( 'OPENID', $assigns );
            $xtpl->parse( 'main.openid.server' );
        }
        
        $xtpl->parse( 'main.openid' );
    }
    
    $xtpl->parse( 'main' );
    
    return $xtpl->text( 'main' );
	
}

?>